package com.data.service.system.impl;

import com.data.domain.manage.Orginfo;
import com.data.domain.manage.OrginfoCriteria;
import com.data.domain.report.Areainfo;
import com.data.domain.report.AreainfoCriteria;
import com.data.domain.report.Bankinfo;
import com.data.domain.report.BankinfoCriteria;
import com.data.josonbean.select.SelectModel;
import com.data.mapper.report.AreainfoMapper;
import com.data.model.BankInfoModel;
import com.data.model.SystemModel;
import com.data.service.system.AreainfoService;
import com.data.utill.DateUtil;
import com.data.utill.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.geom.Area;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service(value = "areainfoService")
public class AreainfoServiceImpl implements AreainfoService {

    @Autowired
    private AreainfoMapper areainfoMapper;

    @Override
    public List<Areainfo> getAreainfo(SystemModel systemModel){
        AreainfoCriteria areainfoCriteria=new AreainfoCriteria();
        AreainfoCriteria.Criteria criteria=areainfoCriteria.createCriteria();
        if(StringUtils.isNoNullString(systemModel.getCode())){
            criteria.andCodeEqualTo(systemModel.getCode());
        }
        if(StringUtils.isNoNullString(systemModel.getName())){
            criteria.andNameLike("%"+systemModel.getName()+"%");
        }
        areainfoCriteria.setOrderByClause("id asc");
        return areainfoMapper.selectByExample(areainfoCriteria);
    }
    /**
     * 地区信息插入
     * @param systemModel
     * @return
     */
    @Override
    public int insertAreainfo(SystemModel systemModel) {
        AreainfoCriteria areainfoCriteria=new AreainfoCriteria();
        Areainfo data = new Areainfo();
//        data.setId(Integer.parseInt(systemModel.getId()));
        data.setCode(systemModel.getCode());
        data.setName(systemModel.getName());
        return areainfoMapper.insertSelective(data);
    }

    /**
     * 地区信息修改
     * @param systemModel
     * @return
     */
    @Override
    public int modifyAreainfo(SystemModel systemModel ,int id) {
        AreainfoCriteria areainfoCriteria=new AreainfoCriteria();
        areainfoCriteria.createCriteria().andIdEqualTo(id);
        Areainfo data = new Areainfo();

//        data.setId(Integer.parseInt(systemModel.getId()));
        data.setCode(systemModel.getCode());
        data.setName(systemModel.getName());
        return areainfoMapper.updateByExampleSelective(data,areainfoCriteria);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Areainfo getAreainfoById(int id) {
        AreainfoCriteria areainfoCriteria=new AreainfoCriteria();
        areainfoCriteria.createCriteria().andIdEqualTo(id);
        List<Areainfo> data = areainfoMapper.selectByExample(areainfoCriteria);
        if (null!=data) {
            return data.get(0);
        }else{
            return null;
        }
    }

    /**
     * 从数据库中取出地区id和地区名称供select2选择
     * @param name
     * @return
     */
    @Override
    public List<SelectModel> selectAreaidAndName(String name){
        AreainfoCriteria areainfoCriteria=new AreainfoCriteria();
        AreainfoCriteria.Criteria criteria=areainfoCriteria.createCriteria();
        if(StringUtils.isNoNullString(name)){
            criteria.andNameLike("%"+name+"%");
        }
        List<Areainfo> list=areainfoMapper.selectByExample(areainfoCriteria);
        List<SelectModel> data = new ArrayList<>();
        SelectModel model=null;
        for(Areainfo areainfo:list){
            model=new SelectModel();
            model.setText(areainfo.getCode()+"-"+areainfo.getName());
            model.setId(areainfo.getCode()+"-"+areainfo.getName());
            data.add(model);
        }
        return data;
    }


}
